package cn.edu.cug.cs.gtl.oi.utils;


import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;
import javax.swing.JPanel;

public abstract class Example extends JPanel
{

    protected Example(){
        mainWindow = new JFrame();
    }
    protected JFrame  mainWindow=null;
    public abstract void start();

    public abstract void stop();

    // called by demo main in stand-alone mode only
    protected void demoMain(String title)
    {
        start();

        this.mainWindow.setTitle(title);
        WindowListener l = new WindowAdapter()
        {
            @Override
            public void windowClosing(WindowEvent e)
            {
                stop();
                mainWindow.dispose();
                System.exit(0);
            }
        };
        mainWindow.addWindowListener(l);
        mainWindow.getContentPane().add(this);

        mainWindow.pack();
        mainWindow.setVisible(true);
    }
}
